package com.gfl.trivialrestclient.services;

import java.util.List;

import com.gfl.trivialrestclient.model.Role;
import com.gfl.trivialrestclient.model.User;

public interface UserService {

	public User getUserByUserName(String username);

	/**
	 * Create user with default role
	 * 
	 * @param user
	 * @return
	 * @throws UserServiceException
	 *             if user with same login already exists
	 */
	public User createUser(User user) throws UserServiceException;

	public boolean isUsernameAvailable(String username);

	/**
	 * Add role to user
	 * 
	 * @param user
	 * @param role
	 * @throws UserServiceException
	 *             if no user or role with such id
	 */
	public void addRoleToUser(User user, Role role) throws UserServiceException;

	/**
	 * Add role to user
	 * 
	 * @param userId
	 * @param roleId
	 * @throws UserServiceException
	 *             if no user or role with such id
	 */
	public void addRoleToUser(Long userId, Long roleId)
			throws UserServiceException;

	/**
	 * Remove role from user
	 * 
	 * @param user
	 * @param role
	 * @throws UserServiceException
	 *             if no user or role with such id
	 */
	public void removeRoleFromUser(User user, Role role)
			throws UserServiceException;

	/**
	 * Remove role from user
	 * 
	 * @param userId
	 * @param roleId
	 * @throws UserServiceException
	 *             if no user or role with such id
	 */
	public void removeRoleFromUser(Long userId, Long roleId)
			throws UserServiceException;

	/**
	 * Remove user
	 * 
	 * @param user
	 * @throws UserServiceException
	 *             if such user not exists
	 */
	public void removeUser(User user) throws UserServiceException;

	/**
	 * Remove role
	 * 
	 * @param role
	 * @throws UserServiceException
	 *             if sucsh role not exists
	 */
	public void removeRole(Role role) throws UserServiceException;

	/**
	 * Remove role
	 * 
	 * @param roleId
	 * @throws UserServiceException
	 *             if role with such id not exists
	 */
	public void removeRole(Long roleId) throws UserServiceException;

	/**
	 * Creates new role or return exsisting role
	 * 
	 * @param roleName
	 * @return
	 */
	public Role createRole(String roleName);

	/**
	 * Finds role by it name
	 * 
	 * @param roleName
	 * @return finded role or null if role with such name not exists
	 */
	public Role getRoleByName(String roleName);

	public List<Role> getAllRoles();

}